package com.sinven.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sinven.pojo.Article;
import com.sinven.pojo.Message;
import com.sinven.pojo.User;
import com.sinven.service.ArticleService;
import com.sinven.service.MessageService;
import com.sinven.service.UserService;

import java.util.List;

/**
 * 评论操作的控制
 * Created by ASUS on 2018/5/27
 *
 * @Authod Grey Wolf
 */

@Controller
@RequestMapping("/user")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
    @Autowired
    private ArticleService articleService;

    @Autowired
    private UserService userinfoService;

    @Autowired
    private ReplyService replyService;
*/
    /**
     * 跳到评论页面
     * @param contentId
     * @param model
     * @return
    
    @RequestMapping("/message")
    public String comment(@RequestParam("contentId")int contentId, Model model){
        System.out.println("id:"+contentId);
        //获取该内容的所有信息
        Article content=articleService.SelectArticleContent(a_id);
        //获取该内容的用户信息
        User userinfo=userinfoService.selectUser(content.getUserid());
        //获取在该内容下的所有评论
        List<Message> commentList=messageService.SelectAllMessageBySelf(m_fromuserId);
        //获取在该内容下的所有回复
        List<Reply>replyList=replyService.selectReply(contentId);
        model.addAttribute("content",content);
        model.addAttribute("user",userinfo);
        model.addAttribute("commentList",commentList);
        model.addAttribute("replyList",replyList);
        return "showContent";

    }

  */
    /**
     * 增加评论
     * @param message
     * @return
     * @throws Exception 
     */
    @RequestMapping("addmessage")
    public String addComment(Message message) throws Exception{
        
        if(message.getM_content()!=null&& !message.getM_content().equals("")) {
            boolean result = messageService.AddMessage(message);
        }
        return "redirect:/user/message?m_touserId="+message.getM_touserId();
    }

   

}

